/*
 * ListenHandler.h
 *
 *  Created on: 2014. 7. 17.
 *      Author: mega
 */

#ifndef GUILDSERVER_LISTENHANDLER_H_
#define GUILDSERVER_LISTENHANDLER_H_

#include "ChannelServer.h"
#include "Static.h"

namespace GuildServer {

class ListenHandler : public Dispatcher::ListenHandler<ChannelServer, Network::Packet>
{
public:
	ListenHandler() {}
	virtual ~ListenHandler() {}

	virtual void OnConnect(ChannelServer* pSession, const char* ip)
	{
		LOG(DEV, "(session_key:", pSession->GetSessionKey(), ", sock:", pSession->GetSocket(), ", ip:", ip, ")");

		GuildServer::Static::Instance().AddChannelServer( pSession );
	}
	virtual void OnClose(ChannelServer* pSession, int nReason)
	{
		LOG(DEV, "(session_key:", pSession->GetSessionKey(), ", sock:", pSession->GetSocket(), ", errno:", nReason, " errstr:", strerror(errno), ")");
		LOG(DEV, "(channel_key:", pSession->GetChannelKey(), ", sock:", pSession->GetSocket(), ", errno:", nReason, " errstr:", strerror(errno), ")");

		GuildServer::Static::Instance().DelChannelServer( pSession->GetSessionKey() );
	}
};

} /*GuildServer*/


#endif /* GUILDSERVER_LISTENHANDLER_H_ */
